<template>
  <base-layout
    :visibleContent2="true"
    :visibleContent3="true"
    :visibleContent4="true"
    :visibleContent5="true"
    :visibleContent6="true"
    :visibleContent7="true"
    :visibleContent8="true"
    :visibleContent9="true"
    :visibleContent10="true"
    :dialogVisible="dialogVisible"
    :dialogTitle="dialogTitle"
    @dialog-close="dialogClose"
    :dialogWidth="dialogWidth"
  >
    <template #searchPanel>
      <el-form
        :inline="true"
        ref="fromdata"
        :show-message="false"
        :hide-required-asterisk="true"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row>
          <el-col :span="22">
            <CustomerSearch
              :disabled="disabled"
              @clientForm="clientForm"
              :singleChoice="fromdata.type"
            />
          </el-col>
          <el-col :span="2">
            <el-button
              type="danger"
              :disabled="disabled"
              v-if="!fromdata.type"
              @click="addType(true)"
              >快速开单</el-button
            >
            <el-button
              type="danger"
              :disabled="disabled"
              v-if="fromdata.type"
              @click="addType(false)"
              >普通开单</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </template>
    <template #contentPanel>
      <el-form
        :inline="true"
        ref="fromdata2"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row class="">
          <el-col>本次进站类型</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-form-item prop="pullInTypes">
            <el-radio-group v-model="fromdata.pullInTypes" :disabled="disabled">
              <el-radio label="一般维修">一般维修</el-radio>
              <el-radio label="索赔">索赔</el-radio>
              <el-radio label="事故">事故</el-radio>
              <el-radio label="保养">保养</el-radio>
              <el-radio label="检查">检查</el-radio>
              <el-radio label="改装">改装</el-radio>
              <el-radio label="续保">续保</el-radio>
              <el-radio label="精品">精品</el-radio>
              <el-radio label="延保">延保</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-row>
      </el-form>
    </template>
    <template #contentPanel2>
      <el-form
        :inline="true"
        ref="fromdata"
        :show-message="false"
        :hide-required-asterisk="true"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
        v-if="!fromdata.type"
        :disabled="disabled"
      >
        <el-row>
          <el-col :span="12">个人信息</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="客户类型:" prop="clientType">
                <el-radio-group v-model="fromdata.clientEntity.clientType">
                  <el-radio-button label="个人客户" border
                    >个人客户</el-radio-button
                  >
                  <el-radio-button label="单位客户" border
                    >单位客户</el-radio-button
                  >
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户名称:" prop="clientName">
                <el-input
                  clearable
                  v-model="fromdata.clientEntity.clientName"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="手机号:" prop="phone">
                <el-input
                  clearable
                  v-model.number="fromdata.clientEntity.phone"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="性别" prop="genderCst">
                <el-radio-group
                  v-model="fromdata.clientEntity.genderCst"
                  style="width: 203px"
                >
                  <el-radio label="男"></el-radio>
                  <el-radio label="女"></el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="会员等级:" prop="memberLevelDictValue">
                <el-input
                  clearable
                  disabled
                  v-model.number="fromdata.clientEntity.memberLevelDictValue"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户来源:" prop="clientSource">
                <el-select
                  clearable
                  style="width: 200px"
                  v-model="fromdata.clientEntity.clientSource"
                  placeholder="客户来源"
                >
                  <el-option
                    v-for="item in dict['客户来源']"
                    :key="item.index"
                    :value="item.value"
                    :label="item.text"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="生日:" prop="birthday">
                <el-date-picker
                  v-model="fromdata.clientEntity.birthday"
                  style="width: 209px"
                  type="datetime"
                  placeholder="生日:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="住址:" prop="address">
                <el-input
                  clearable
                  v-model.number="fromdata.clientEntity.address"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="客户门店:" prop="storeId">
                <Job-shop
                  v-model="fromdata.clientEntity.storeId"
                  :defaultStoreId="true"
                  placeholder="客户门店"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="备注:" prop="remark">
                <el-input
                  clearable
                  v-model="fromdata.clientEntity.remark"
                  class="w-200"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
      <!-- 车辆信息 -->
      <el-form
        :inline="true"
        ref="fromdata1"
        :model="fromdata"
        :rules="rules"
        label-width="100px"
        label-position="right"
        v-if="fromdata.type"
        :disabled="disabled"
      >
        <el-row>
          <el-col :span="12">车辆信息</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="送修人:" prop="giveType">
                <el-radio-group v-model="fromdata.giveType">
                  <el-radio-button :label="true" border>车主</el-radio-button>
                  <el-radio-button :label="false" border>他人</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="送修人姓名:" prop="sendRepairName">
                <el-input clearable v-model="fromdata.sendRepairName" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="联系方式:" prop="sendRepairPhone">
                <el-input clearable v-model.number="fromdata.sendRepairPhone" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="入场里程数:" prop="inFactoryMileage">
                <el-input
                  clearable
                  v-model.number="fromdata.inFactoryMileage"
                  style="width: 200px"
                >
                  <template slot="append">KM</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="入场油量:" prop="inFactoryOil">
                <OilNum v-model="fromdata.inFactoryOil" :disabled="disabled" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="接车时间:" prop="receiveCarTime">
                <el-date-picker
                  v-model="fromdata.receiveCarTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="接车时间:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车型:" prop="carModel">
                <CarModel v-model="carModels" ref="carModel" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="车牌号:" prop="licensePlateNumber">
                <el-input clearable v-model="fromdata.licensePlateNumber" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="服务接待:" prop="receptionName">
                <el-input
                  clearable
                  v-model="fromdata.receptionName"
                  @focus="addEmploye"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
    </template>

    <template #contentPanel3>
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
        v-if="!fromdata.type"
      >
        <el-row class="">
          <el-col :span="22">客户车辆列表</el-col>
          <el-col :span="2">
            <el-button
              icon="el-icon-plus"
              type="primary"
              @click="addCars"
              v-if="!disabled"
              >新增车辆</el-button
            >
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <data-table
            :value="fromdata.clientCarsEntities"
            :has-action="true"
            :total-count="fromdata.clientCarsEntities.length"
            :table-column-attributes="tableColumnAttributes"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :width="160"
            :localPage="true"
          >
            <template #action="{ row }" v-if="!disabled">
              <i
                class="el-icon-edit"
                title="编辑"
                style="cursor: pointer"
                @click="editCarInfo(row, '编辑')"
              ></i>
              <i
                class="el-icon-delete"
                title="删除"
                style="color: red; margin-left: 20px; cursor: pointer"
                @click="deleteCarInfo(row)"
              ></i>
            </template>
          </data-table>
        </el-row>
      </el-form>

      <!-- 快速单工单信息 -->
      <el-form
        :inline="true"
        ref="fromdata1"
        :model="fromdata"
        :rules="rules"
        label-width="100px"
        label-position="right"
        v-if="fromdata.type"
        :disabled="disabled"
      >
        <el-row class="">
          <el-col :span="22">工单信息</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="工单编号:" prop="workOrderCode">
                <el-input clearable v-model="fromdata.workOrderCode" readonly />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据日期:" prop="receiptsTime">
                <el-date-picker
                  disabled
                  v-model="fromdata.receiptsTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="单据日期:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
    </template>

    <template #contentPanel4 v-if="!fromdata.type">
      <el-form
        :inline="true"
        ref="fromdata1"
        :model="fromdata"
        :rules="rules"
        label-width="110px"
        label-position="right"
        :disabled="disabled"
      >
        <el-row>
          <el-col :span="12">工单信息</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="工单编号:" prop="workOrderCode">
                <el-input clearable v-model="fromdata.workOrderCode" readonly />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="送修人:" prop="giveType">
                <el-radio-group v-model="fromdata.giveType">
                  <el-radio-button :label="true" border>车主</el-radio-button>
                  <el-radio-button :label="false" border>他人</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="送修人姓名:" prop="sendRepairName">
                <el-input clearable v-model="fromdata.sendRepairName" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="联系方式:" prop="sendRepairPhone">
                <el-input clearable v-model.number="fromdata.sendRepairPhone" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="入场里程数:" prop="inFactoryMileage">
                <el-input
                  clearable
                  v-model.number="fromdata.inFactoryMileage"
                  style="width: 200px"
                >
                  <template slot="append">KM</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="入场油量:" prop="inFactoryOil">
                <OilNum v-model="fromdata.inFactoryOil" :disabled="disabled" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="接车时间:" prop="receiveCarTime">
                <el-date-picker
                  v-model="fromdata.receiveCarTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="接车时间:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预计交车:" prop="predictDeliveryTime">
                <el-date-picker
                  v-model="fromdata.predictDeliveryTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="预计交车:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="服务接待:" prop="receptionName">
                <el-input
                  clearable
                  v-model="fromdata.receptionName"
                  @focus="addEmploye"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据日期:" prop="receiptsTime">
                <el-date-picker
                  disabled
                  v-model="fromdata.receiptsTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="单据日期:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6" v-show="fromdata.pullInTypes == '事故'">
              <el-form-item label="保险公司:" prop="insuranceCompany">
                <el-input clearable v-model="fromdata.insuranceCompany" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>

        <el-row v-if="fromdata.pullInTypes == '索赔'">
            <el-col :span="6">
              <el-form-item label="发动机型号:" prop="engineModel">
                <el-input clearable v-model="fromdata.engineModel" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车辆生产日期:" prop="productionDate" label-width="120px">
                <el-date-picker
                  disabled
                  v-model="fromdata.productionDate"
                  style="width: 189px"
                  type="datetime"
                  placeholder="车辆生产日期:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="是否加装/改装:" prop="refitFlag" label-width="120px">
                <el-radio-group v-model="fromdata.refitFlag" style="width: 160px">
                  <el-radio :label="true">是</el-radio>
                  <el-radio :label="false">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车辆性质:" prop="carNature">
                <el-select
                  clearable
                  ref="dragSelect"
                  v-model="fromdata.carNature"
                  class="drag-select"
                >
                  <el-option
                    v-for="item in ['运营车辆', '非运营车辆']"
                    :key="item"
                    :value="item"
                    :label="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="案件优先级:" prop="casePriority">
                <el-radio-group v-model="fromdata.casePriority" style="width: 220px">
                  <el-radio :label="1">三包</el-radio>
                  <el-radio :label="2">紧急</el-radio>
                  <el-radio :label="3">一般</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="下次保养里程数:" prop="maintainMileage">
                <el-input
                  clearable
                  v-model.number="fromdata.maintainMileage"
                  style="width: 200px"
                >
                  <template slot="append">KM</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预计下次保养日期:" prop="maintainDate">
                <el-date-picker
                  v-model="fromdata.maintainDate"
                  style="width: 209px"
                  type="datetime"
                  placeholder="预计下次保养日期:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="离店时间:" prop="departureTime">
                <el-date-picker
                  v-model="fromdata.departureTime"
                  style="width: 209px"
                  type="datetime"
                  placeholder="离店时间:"
                  value-format="yyyy-MM-dd hh:mm:ss"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="在店时间:" prop="inStoreStr">
                <el-input
                  disabled
                  clearable
                  v-model="fromdata.inStoreStr"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="经销商名称:" prop="distributorName">
                <el-input
                  clearable
                  v-model="fromdata.distributorName"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="经销商联系电话:" prop="distributorPhone">
                <el-input
                  clearable
                  v-model="fromdata.distributorPhone"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12" >
              <el-form-item label="主因配件:" prop="reasonParts">
                <el-input
                  type="textarea"
                  style="width: 500px"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="fromdata.reasonParts">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" >
              <el-form-item label="诊断步骤:" prop="diagnosticSteps">
                <el-input
                  type="textarea"
                  style="width: 500px"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="fromdata.diagnosticSteps">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" >
              <el-form-item label="维修结论:" prop="repairConclusion">
                <el-input
                  style="width: 500px"
                  type="textarea"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="fromdata.repairConclusion">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" >
              <el-form-item label="是否咨询内容/进销商备注:" prop="consultContent">
                <el-input
                  type="textarea"
                  style="width: 500px"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="fromdata.consultContent">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

      </el-form>
    </template>
    <template #contentPanel5>
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
        :disabled="disabled"
      >
        <el-row>
          <el-col :span="12">故障描述（维修建议）</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户描述:" prop="faultDescClient">
              <keep-alive>
                <Tinymce
                  v-if="showTinymce"
                  v-model="fromdata.faultDescClient"
                  :id="'13542asdfsaf6'"
                  :height="300"
                />
              </keep-alive>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="初步诊断:" prop="faultDescInitial">
              <keep-alive>
                <Tinymce
                  v-if="showTinymce"
                  v-model="fromdata.faultDescInitial"
                  :id="'13542asdfsaf6234'"
                  :height="300"
                />
              </keep-alive>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </template>

    <template #contentPanel6 v-if="fromdata.pullInTypes == '索赔'">
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="140px"
        label-position="right"
        :disabled="disabled"
      >
        <el-row>
          <el-col :span="12">故障详细描述</el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form-item label="故障现象:" prop="fault">
              <el-radio-group v-model="fromdata.fault">
                <el-radio label="无法启动">无法启动</el-radio>
                <el-radio label="动力不足">动力不足</el-radio>
                <el-radio label="漏水">漏水</el-radio>
                <el-radio label="漏油">漏油</el-radio>
                <el-radio label="震动">震动</el-radio>
                <el-radio label="换挡质量">换挡质量</el-radio>
                <el-radio label="跑偏">跑偏</el-radio>
                <el-radio label="空调性能">空调性能</el-radio>
                <el-radio label="电子电器性能">电子电器性能</el-radio>
                <el-radio label="车身稳定">车身稳定</el-radio>
                <el-radio label="其它">其它</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="故障部位:" prop="faultPosition">
              <!-- <el-select  clearable v-model="fromdata.faultPosition" class="drag-select">
                <el-option
                  v-for="item in faultPositionOptions"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select> -->
              <el-input clearable v-model="fromdata.faultPosition"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中分类:" prop="inCategory">
              <!-- <el-select  clearable  v-model="fromdata.inCategory" class="drag-select">
                <el-option
                  v-for="item in inCategoryOptions"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select> -->
              <el-input clearable v-model="fromdata.inCategory"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="症状:" prop="symptom">
              <!-- <el-select  clearable v-model="fromdata.symptom" class="drag-select">
                <el-option
                  v-for="item in symptomOptions"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select> -->
              <el-input clearable v-model="fromdata.symptom"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出现频率:" prop="frequency">
              <!-- <el-select  clearable v-model="fromdata.frequency" class="drag-select">
                <el-option
                  v-for="item in frequencyOptions"
                  :key="item"
                  :value="item"
                  :label="item"
                />
              </el-select> -->
              <el-input clearable v-model="fromdata.frequency"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="故障是否可验证:" prop="testFlag">
              <el-radio-group v-model="fromdata.testFlag" style="width: 200px">
                <el-radio :label="true">是</el-radio>
                <el-radio :label="false">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="诊断仪版本号:" prop="instrumentVersion">
              <el-input clearable v-model="fromdata.instrumentVersion"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否有故障码信息:" prop="faultInfoFlag">
              <el-radio-group v-model="fromdata.faultInfoFlag" style="width: 200px">
                <el-radio :label="true">是</el-radio>
                <el-radio :label="false">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="故障时天气状况:" prop="faultWeather">
              <el-select  clearable v-model="fromdata.faultWeather" class="drag-select">
                <el-option
                  v-for="item in faultWeatherOptions"
                  :key="item"
                  :value="item"
                  :label="item"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="故障时车速:" prop="faultSpeed">
              <el-input clearable v-model="fromdata.faultSpeed"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发动机转速:" prop="engineSpeed">
              <el-input clearable v-model="fromdata.engineSpeed"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="日常行驶路况(多选):" prop="dailyRoads">
              <el-checkbox-group v-model="fromdata.dailyRoadsList">
                <el-checkbox label="一般路面">一般路面</el-checkbox>
                <el-checkbox label="复杂路面">复杂路面</el-checkbox>
                <el-checkbox label="高速路面">高速路面</el-checkbox>
                <el-checkbox label="山区">山区</el-checkbox>
                <el-checkbox label="郊区">郊区</el-checkbox>
                <el-checkbox label="市区">市区</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="故障时路况(多选):" prop="faultRoads">
              <el-checkbox-group v-model="fromdata.faultRoadsList">
                <el-checkbox label="颠簸">颠簸</el-checkbox>
                <el-checkbox label="山坡">山坡</el-checkbox>
                <el-checkbox label="下坡">下坡</el-checkbox>
                <el-checkbox label="弯道">弯道</el-checkbox>
                <el-checkbox label="平路">平路</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </template>

    <template #contentPanel7>
      <el-form
        :inline="true"
        ref="fromdata"
        :show-message="false"
        :hide-required-asterisk="true"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row>
          <el-col :span="12">外部检测</el-col>
          <el-divider content-position="center"></el-divider>
          <el-col>
            <ExternalInspection
              ref="externalInspection"
              :orderPickCarId="fromdata.id"
              :data="fromdata.orderPickCarOutCheckLists"
              :disabled="disabled"
            />
          </el-col>
        </el-row>
      </el-form>
    </template>
    <template #contentPanel8>
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row>
          <el-row class="">
            <el-col :span="22">内部检测</el-col>
            <el-col :span="2">
              <el-button
                icon="el-icon-plus"
                type="primary"
                @click="addItem"
                v-if="!disabled"
                >选择检测项</el-button
              >
            </el-col>
          </el-row>
          <el-divider content-position="center"></el-divider>
          <el-row>
            <data-table
              :value="fromdata.orderPickCarInCheckLists"
              :total-count="fromdata.orderPickCarInCheckLists.length"
              :has-action="true"
              :table-column-attributes="inTable"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :width="160"
              :localPage="true"
            >
              <template #action="{ row }" v-if="!disabled">
                <i
                  class="el-icon-delete"
                  title="删除"
                  style="color: red; margin-left: 20px; cursor: pointer"
                  @click="deleteItem(row)"
                ></i>
              </template>
            </data-table>
          </el-row>
        </el-row>
      </el-form>
    </template>
    <template #contentPanel9>
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row>
          <el-col :span="12">上传文件</el-col>
          <el-divider content-position="center"></el-divider>
          <el-upload
            action=""
            list-type="picture-card"
            :http-request="httpRequest"
            :fileList="fileList"
            :disabled="disabled"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog
            class="preview-modal"
            :visible.sync="imgVisible"
            append-to-body
          >
            <img width="100%" :src="dialogImageUrl" alt="photo" />
          </el-dialog>
        </el-row>
      </el-form>
    </template>
    <template #contentPanel10>
      <el-form
        :inline="true"
        ref="fromdata"
        :model="fromdata"
        :rules="rules"
        label-width="90px"
        label-position="right"
      >
        <el-row>
          <el-col :span="12">检测备注</el-col>
          <el-divider content-position="center"></el-divider>
          <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入内容"
            v-model="fromdata.note"
          >
          </el-input>
        </el-row>
        <el-row style="margin-top: 20px">
          <el-col :span="24" align="right" justify="center">
            <el-button type="primary" @click="turnWork" v-if="disabled"
              >转工单</el-button
            >
            <el-button type="danger" @click="print" v-if="disabled"
              >打印接车单</el-button
            >
            <el-button type="success" @click="saveUpdate" v-if="!disabled"
              >检测保存</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </template>
    <template #dialog>
      <DialogDataForm
        v-if="showData"
        :value="currentCar"
        :type="type"
        @operate="sendCarInfo"
      />
      <SelectCheckItem v-if="showCheckItem" @selectItem="selectItem" />
      <EmployeeTable
        v-if="showEmployeeTable"
        @roleIdListSelectCheck="employeListSelectCheck"
        :checkList="[fromdata.manageUserName]"
      />
      <el-row v-if="showTurnWork">
        <el-form
          :inline="true"
          ref="fromdata4"
          :model="turnWorkFrom"
          :rules="turnRules"
          label-width="200px"
          label-position="right"
        >
          <el-row>
            <el-form-item label="接车单单号:">
              <div style="color: red">{{ fromdata.workOrderCode }}</div>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item
              label="请选择接车单转工单类型:"
              prop="workTypeRadio"
              required
            >
              <el-radio-group v-model="turnWorkFrom.workTypeRadio" size="mini">
                <el-row>
                  <el-radio label="综合单" border>综合单</el-radio>
                  <el-radio label="快速单" border>快速单</el-radio>
                  <el-radio label="洗车单" border>洗车单</el-radio>
                </el-row>
                <el-row style="margin-top: 10px">
                  <el-radio label="报价单" border>报价单</el-radio>
                  <el-radio label="销售单" border>销售单</el-radio>
                  <el-radio label="保险单" border>保险单</el-radio>
                </el-row>
              </el-radio-group>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="23" align="right" justify="center">
              <el-button type="success" @click="confimTurnWork"
                >确认转工单</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </el-row>
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import { CustomerSearch, CarModel, OilNum } from '@/components/index'
import Tinymce from '@/components/Tinymce'
import EmployeeTable from '../../systemManage/store/components/EmployeeTable'
import {
  update,
  add,
  getWorkOrderCode,
  getFindById,
} from '@/api/after-sale/workOrderManage/pickUpOrder'
import { getClientById } from '@/api/after-sale/client/client'
import {
  getDict,
  getStoreId,
  fileUpload,
  getImageUrl,
  exportFile,
  getDateDiff
} from '@/utils'
import store from '@/store'
import DialogDataForm from '../../client-manage/edit/components/DialogDataForm'
import SelectCheckItem from '@/components/SelectCheckItem/index'
import ExternalInspection from './components/externalInspection'
import { findOrderByPickCarId } from '@/api/after-sale/workOrderManage/orderManage'
import moment from 'moment'
export default {
  components: {
    CustomerSearch,
    EmployeeTable,
    Tinymce,
    DialogDataForm,
    SelectCheckItem,
    CarModel,
    ExternalInspection,
    OilNum,
  },
  mixins: [
    baseMixin({
      addData: add,
      updateData: update,
      format(res) {
        return res.map((data) => {
          return data
        })
      },
    }),
  ],
  data() {
    return {
      fromdata: {
        id: '',
        workOrderCode: '',
        type: false, // 是否快速开单 true是
        clientEntity: {
          storeId: null,
        }, // 员工信息
        clientCarsEntities: [], // 车辆信息
        orderPickCarInCheckLists: [], // 内部检测
        orderPickCarOutCheckLists: [], // 外部检测
        sendRepairName: null,
        sendRepairPhone: null,
        receptionName: null,
        clientId: null,
        photos: null,
        photosList: [],
        faultDescInitial: null,
        faultDescClient: null,
        pullInTypes: '一般维修',
        dailyRoadsList: [],
        faultRoadsList: [],
        maintainDate: null,
        departureTime: null,
        testFlag: null,
        repairConclusion: '',
        reasonParts: '',
        maintainMileage: null,
        instrumentVersion: null,
        inFactoryMileage: null,
        frequency: null,
        faultWeather: null,
        faultSpeed: null,
        faultRoads: null,
        faultPosition: null,
        faultInfoFlag: null,
        faultDescInitial: null,
        faultDescClient: null,
        fault: null,
        engineSpeed: null,
        casePriority: null,
        carNature: null,
        consultContent: '',
        diagnosticSteps: '',
        distributorName: '',
        distributorPhone: null,
        engineModel: null,
        insuranceCompany: null,
        refitFlag:null,
        giveType: null,
        receiveCarTime: null,
        inFactoryOil: null,
        receiptsTime: null
      },
      showTinymce: true, // 故障描述输入框渲染
      carModels: [], // 车型数据
      fileList: [],
      rescuePhoneDis: false,
      levelDis: false,
      showData: false, // 是否展示车辆弹窗
      showCheckItem: true, // 是否展示检测项
      showEmployeeTable: false, // 是否展示选择检查员
      showTurnWork: false, // 转工单弹窗
      imgVisible: false, // 图片预览
      checkId: null, // 选择检测员时当前数据的id
      tableColumnAttributes: [
        { name: '车牌号', value: 'licensePlateNumber', type: 'text' },
        { name: '品牌', value: 'carBrandName', type: 'text' },
        { name: '车系', value: 'carSeriesName', type: 'text' },
        { name: '年款', value: 'timeType', type: 'text' },
        { name: '车型', value: 'carModelName', type: 'text' },
        { name: '车色', value: 'carColor', type: 'text' },
        { name: '里程数', value: 'mileage', type: 'text' },
        { name: '交强险公司', value: 'companyName', type: 'text' },
        { name: '交强险到期', value: 'insureExpireDate', type: 'text' },
        { name: '备注', value: 'remark', type: 'text' },
        { name: '录入时间', value: 'createTime', type: 'text' },
      ],
      inTable: [
        { name: '检查项目', value: 'checkProject', type: 'text' },
        { name: '检查细节描述', value: 'checkDesc', type: 'text' },
        { name: '检查种类', value: 'checkKind', type: 'text' },
        { name: '状态', value: 'status', type: 'radioGroup', disabled: false },
        {
          name: '检查员',
          value: 'checkUserName',
          type: 'input',
          focus: this.addEmploye,
        },
        { name: '备注', value: 'remark', type: 'input' },
      ],
      rules: {
        workOrderCode: [
          { required: true, message: '工单编号为空', trigger: 'blur' },
        ],
        receiveCarTime: [
          { required: true, message: '请选择接车时间', trigger: 'change' },
        ],
        receiptsTime: [
          { required: true, message: '请选择单据日期', trigger: 'blur' },
        ],
        receptionName: [
          { required: true, message: '请选择服务接待', trigger: 'change' },
        ],
        giveType: [
          { required: true, message: '请选择送修人', trigger: 'change' },
        ],
        sendRepairName: [
          { required: true, message: '请填写送修人姓名', trigger: 'change' },
        ],
        sendRepairPhone: [
          { required: true, message: '请填写送修人电话', trigger: 'change' },
        ],
        inFactoryMileage: [
          { required: true, message: '请填写入厂里程数', trigger: 'blur' },
        ],
        inFactoryOil: [
          { required: true, message: '请填写入厂里油量', trigger: 'blur' },
        ],
        pullInTypes: [
          { required: true, message: '请选择本次进站类型', trigger: 'change' },
        ],
      },
      type: '',
      currentCar: {},
      dialogImageUrl: '',
      imageDialogVisible: false,
      dict: [],
      disabled: false,
      dialogWidth: '1300px', // 弹窗宽度
      turnWorkFrom: {
        workTypeRadio: null, // 转工单类型
        pickCarId: null, // 接车单id
      },
      turnRules: {
        workTypeRadio: [
          { required: true, message: '请选择转工单类型', trigger: 'blur' },
        ],
      },
      // faultPositionOptions: [
      //   {label: 'C001发动机', value: 'C001'},
      //   {label: 'C002音响系统和卫星导航系统', value: 'C002'},
      //   {label: 'C003悬挂，车轮，转动轴', value: 'C003'},
      //   {label: 'C004转向', value: 'C004'},
      //   {label: 'C005制动', value: 'C005'},
      //   {label: 'C006变速箱（AT/MT/DDCT/si-EVT），离合器', value: 'C006'},
      //   {label: 'C007肉眼可是缺陷', value: 'C007'},
      //   {label: 'C008车体油漆', value: 'C008'},
      //   {label: 'C009电气，暖风，空调，仪表（电器），车联网', value: 'C009'},
      //   {label: 'C010仪表（硬件），内外饰，车身', value: 'C0010'},
      //   {label: 'C011FFV', value: 'C0011'},
      //   {label: 'C012客述日报', value: 'C0012'},
      // ],
      // inCategoryOptions:[
      //   {label: 'MC01CD播放机', value: 'MC01'},
      //   {label: 'MC02操作性', value: 'MC02'},
      //   {label: 'MC03传动性能（A/T）', value: 'MC03'},
      //   {label: 'MC04怠速', value: 'MC04'},
      //   {label: 'MC05电气-车身，排气', value: 'MC05'},
      //   {label: 'MC06电气-发动机', value: 'MC06'},
      //   {label: 'MC07发动机性能', value: 'MC07'},
      //   {label: 'MC08分离', value: 'MC08'},
      //   {label: 'MC09故障（功能，作动不良）', value: 'MC09'},
      //   {label: 'MC10盒式磁带播放机', value: 'MC10'},
      //   {label: 'MC100FFV', value: 'MC100'},
      //   {label: 'MC101客诉日报', value: 'MC101'},
      //   {label: 'MC11均衡器', value: 'MC11'},
      //   {label: 'MC12离合器功能（A/T除外）', value: 'MC12'},
      //   {label: 'MC13漏水，漏风', value: 'MC13'},
      //   {label: 'MC14磨损', value: 'MC14'},
      //   {label: 'MC15启动性能', value: 'MC15'},
      //   {label: 'MC17烧损，异味，臭味', value: 'MC17'},
      //   {label: 'MC18收音机', value: 'MC18'},
      //   {label: 'MC19外观不良', value: 'MC19'},
      //   {label: 'MC20卫星导航仪', value: 'MC20'},
      //   {label: 'MC21泄露', value: 'MC21'},
      //   {label: 'MC22扬声器', value: 'MC22'},
      //   {label: 'MC23仪表，时钟', value: 'MC23'},
      //   {label: 'MC24音响-共同部分', value: 'MC24'},
      //   {label: 'MC25油漆不良，油漆缺陷', value: 'MC25'},
      //   {label: 'MC26噪音，振动', value: 'MC26'},
      //   {label: 'MC28传动功能（M/T）', value: 'MC28'},
      //   {label: 'MC99其他', value: 'MC99'},
      // ],
      // symptomOptions:[
      //   {label: '001凹痕', value: '001'},
      //   {label: '002弯曲', value: '002'},
      //   {label: '003伸长', value: '003'},
      //   {label: '004变形扭曲', value: '004'},
      //   {label: '005磨损', value: '005'},
      //   {label: '006油漆缺陷', value: '006'},
      //   {label: '007穿孔', value: '007'},
      //   {label: '008腐蚀，锈蚀', value: '008'},
      //   {label: '009褪色(油漆除外)', value: '009'},
      //   {label: '010电镀不良', value: '010'},
      //   {label: '011劣化', value: '011'},
      //   {label: '012效率低下，弱', value: '012'},
      //   {label: '013雾气', value: '013'},
      //   {label: '014切伤', value: '014'},
      //   {label: '026切断', value: '026'},
      //   {label: '027超出限制值', value: '027'},
      //   {label: '028螺纹脱扣/脱丝', value: '028'},
      //   {label: '029重设失败/脱丝', value: '029'},
      //   {label: '031入档困难', value: '031'},
      //   {label: '032作动不良', value: '032'},
      //   {label: '038溢出', value: '038'},
      //   {label: '039指示不良', value: '039'},
      //   {label: '040仪表指针振动', value: '040'},
      //   {label: '041换档不同步(打齿声', value: '041'},
      //   {label: '042异响', value: '042'},
      //   {label: '045振动', value: '045'},
      //   {label: '049间隙过大', value: '049'},
      //   {label: '051机油泄漏', value: '051'},
      //   {label: '052压力泄露', value: '052'},
      //   {label: '053延迟', value: '053'},
      //   {label: '055振动', value: '055'},
      //   {label: '056风切音(漏气)', value: '056'},
      //   {label: '057分开，分离', value: '057'},
      //   {label: '058白浊', value: '058'},
      //   {label: '059漏水', value: '059'},
      //   {label: '060泄漏(冷却液，汽油，真空等)', value: '060'},
      //   {label: '084颜色不调', value: '084'},
      //   {label: '085变色，褪色(仅用于油漆)', value: '085'},
      //   {label: '086剥落', value: '086'},
      //   {label: '087流泪', value: '087'},
      //   {label: '088涂膜薄，裸露', value: '088'},
      //   {label: '089功率不足', value: '089'},
      //   {label: '090启动困难', value: '090'},
      //   {label: '091发动机性能不良', value: '091'},
      //   {label: '092加速不良，缺乏动力', value: '092'},
      //   {label: '093发动机熄火', value: '093'},
      //   {label: '094机油消耗大', value: '094'},
      //   {label: '095冒烟', value: '095'},
      //   {label: '096燃料消耗大', value: '096'},
      //   {label: '097操作性不稳定', value: '097'},
      //   {label: '099其他', value: '099'},
      //   {label: '100 FFV', value: '100'},
      //   {label: '101客诉日报', value: '101'},
      // ],
      frequencyOptions: ['持续','间歇','经常','偶发'],
      faultWeatherOptions:['阴天','晴天','下雨','下雪']
    }
  },
  watch: {
    // 车主监听
    'fromdata.giveType': function (value) {
      if (value) {
        this.fromdata.sendRepairName = this.fromdata.clientEntity.clientName
        this.fromdata.sendRepairPhone = this.fromdata.clientEntity.phone
      } else {
        this.fromdata.sendRepairName = null
        this.fromdata.sendRepairPhone = null
      }
    },
    fromdata: {
      deep: true,
      immediate: true,
      handler(value) {
        if (value.pullInTypes == '索赔') {
          if (value.receiveCarTime && value.departureTime) {
            this.fromdata.inStoreStr = getDateDiff(value.receiveCarTime, value.departureTime).toFixed() + '天';
          }
        }
      },
    },
  },
  methods: {
    // 快速开单
    addType(value) {
      let id = this.$route.query.id
      // 重置表单
      this.fromdata = {
        id: id ? id : '',
        workOrderCode: '',
        type: value, // 是否快速开单 true是
        clientEntity: {}, // 员工信息
        clientCarsEntities: [], // 车辆信息
        orderPickCarInCheckLists: [], // 内部检测
        orderPickCarOutCheckLists: [], // 外部检测
        photos: [],
      }
      this.getWorkOrderCode()
    },
    // 打印
    print() {
      exportFile(
        `${process.env.BASE_API}/order/print/${this.$route.query.id}/接车单`,
        `接车单.pdf`
      )
    },
    // 确认转工单
    confimTurnWork() {
      this.$refs['fromdata4'].validate((valid) => {
        if (valid) {
          findOrderByPickCarId(this.turnWorkFrom).then((res) => {
            let { success, data } = res
            data.id = null
            if (success) {
              switch (this.turnWorkFrom.workTypeRadio) {
                case '综合单':
                  this.turnRoute('/workOrderManage/create-comprehensive', data)
                  break
                case '保险单':
                  this.turnRoute('/workOrderManage/addInsuranceOrder', data)
                  break
                case '快速单':
                  this.turnRoute('/workOrderManage/create-fast', data)
                  break
                case '洗车单':
                  this.turnRoute('/workOrderManage/create-car-wash', data)
                  break
                case '报价单':
                  this.turnRoute('/workOrderManage/create-quotation', data)
                  break
                case '销售单':
                  this.turnRoute('/workOrderManage/create-sell', data)
                  break
              }
            }
          })
        }
      })
    },
    // 跳转路由
    turnRoute(path, data) {
      this.$router.push({
        path: path,
        query: {
          id: data.id,
          data: data,
          pickCarId: data.pickCarId,
        },
      })
    },
    // 转工单弹窗
    turnWork() {
      this.showData = false
      this.showCheckItem = false
      this.showEmployeeTable = false
      this.showTurnWork = true
      this.dialogWidth = '600px'
      this.handleDataInsert('转工单')
    },
    //覆盖文件默认上传行为
    httpRequest(value) {
      let fileName=value.file.name;
      let fileType=fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
      fileUpload(value.file,fileType).then((res) => {
        let { success, data } = res
        if (success) {
          if (this.fromdata.photosList == null) {
            this.fromdata.photosList = []
          }
          this.fromdata.photosList.push(data.id)
        }
      })
    },
    // 客户返回值
    clientForm(value) {
      console.log('客户返回数据：', value)
      if (value) {
        this.fromdata.clientEntity = { ...value, cars: null }
        this.fromdata.clientId = this.fromdata.clientEntity.id
        // 快速开单
        if (this.fromdata.type) {
          let car = value.cars
          this.fromdata.clientCarsEntities.push(car)
          this.fromdata.licensePlateNumber = car.licensePlateNumber
          this.carModels = [
            car.carBrandId,
            car.carSeriesId,
            car.timeType,
            car.carModelId,
          ]
        } else {
          this.fromdata.clientCarsEntities = value.cars
        }
      }
    },
    // 保存或者更新
    saveUpdate() {
      this.fromdata.orderPickCarOutCheckLists = this.$refs.externalInspection.list //获取外部检测数据
      this.$refs['fromdata1'].validate((valid) => {
        this.$refs['fromdata2'].validate((valid1) => {
          if (valid && valid1) {
            this.fromdata.storeId = getStoreId()
            if (this.fromdata.type) {
              // 快速单组装车辆信息
              this.fromdata.clientCarsEntities[0].licensePlateNumber = this.fromdata.licensePlateNumber
              this.fromdata.clientCarsEntities[0].carBrandId = this.carModels[3]
              this.fromdata.clientCarsEntities[0].carSeriesId = this.carModels[1]
              this.fromdata.clientCarsEntities[0].timeType = this.carModels[2]
              this.fromdata.clientCarsEntities[0].carBrandId = this.carModels[0]
            }
            if (this.fromdata.pullInTypes == '索赔') {
              this.fromdata.faultRoads = this.fromdata.faultRoadsList.join(',');
              this.fromdata.dailyRoads = this.fromdata.dailyRoadsList.join(',');
              this.fromdata.inStore = this.fromdata.inStoreStr ? parseInt(this.fromdata.inStoreStr, 10) : null;
            }
            this.fromdata.photos = this.fromdata.photosList && this.fromdata.photosList.toString(',')
            this.handleDataUpdate(this.fromdata)
            this.closeRouter('/workOrderManage/pickUpOrder')
          }
        })
      })
    },
    // 新增车辆弹窗
    addCars() {
      this.showData = true
      this.showCheckItem = false
      this.showEmployeeTable = false
      this.showTurnWork = false
      this.type = 'add'
      this.handleDataInsert('新增车辆')
    },
    // 选择检测员
    async addEmploye(row) {
      if (row) {
        this.checkId = row.id
      }
      this.showData = false
      this.showCheckItem = false
      this.showTurnWork = false
      this.showEmployeeTable = true
      this.handleDataInsert('检查员')
    },
    //员工选择
    employeListSelectCheck(select) {
      if (this.checkId) {
        this.fromdata.orderPickCarInCheckLists.forEach((e, i) => {
          if (e.id === this.checkId) {
            this.$set(
              this.fromdata.orderPickCarInCheckLists[i],
              'checkUserName',
              select[0].userName
            )
            this.$set(
              this.fromdata.orderPickCarInCheckLists[i],
              'userId',
              select[0].id
            )
          }
        })
        this.checkId = null
      } else {
        this.fromdata.receptionName = select[0].userName
        this.fromdata.receptionId = select[0].id
      }
      this.dialogClose()
    },
    // 删除车辆
    deleteCarInfo(row) {
      this.fromdata.clientCarsEntities = this.fromdata.clientCarsEntities.filter(
        (e) => e != row
      )
    },
    // 编辑车辆
    editCarInfo(row) {
      this.showData = true
      this.showCheckItem = false
      this.showEmployeeTable = false
      this.showTurnWork = false
      this.currentCar = row
      this.type = 'edit'
      this.handleDataInsert('编辑车辆')
    },
    // 车辆选择
    sendCarInfo(val, type) {
      let newCars = this.fromdata.clientCarsEntities
      if (type == 'add') {
        newCars.unshift(val)
      } else if (type == 'edit') {
        newCars = newCars.map((e) => {
          if (e.id == this.currentCar.id) {
            return val
          }
        })
      }
      this.fromdata.clientCarsEntities = [...newCars]
      this.dialogClose()
    },
    // 添加检测项
    addItem() {
      this.showData = false
      this.showCheckItem = true
      this.showEmployeeTable = false
      this.handleDataInsert('选择内部检测项目')
    },
    async getWorkOrderCode() {
      let { data } = await getWorkOrderCode()
      this.fromdata.workOrderCode = data
    },
    // 监听检测选择项值
    selectItem(value) {
      let loginUserInfo = JSON.parse(sessionStorage.getItem('login'))
      value.forEach((e) => {
        let index = true
        this.fromdata.orderPickCarInCheckLists.forEach((g) => {
          if (e.id === g.id) {
            index = false
          }
        })
        if (index) {
          let { ...data } = {
            ...e,
            checkDesc: e.projectDesc,
            checkKind: e.projectType,
            checkProject: e.projectName,
            //ymc 20210116 赋值默认值 操作人为当前登录人
            checkUserName: loginUserInfo.userName,
            userId: loginUserInfo.id,
          }
          this.fromdata.orderPickCarInCheckLists.push(data)
        }
      })
      this.dialogClose()
    },
    // 删除检测项
    deleteItem(row) {
      this.fromdata.orderPickCarInCheckLists = this.fromdata.orderPickCarInCheckLists.filter(
        (e) => e.id != row.id
      )
    },
    async detail(id) {
      let { data } = await getFindById(id)
      this.fromdata = Object.assign(this.fromdata, data);
      if (this.fromdata.type) {
        this.fromdata.licensePlateNumber = this.fromdata.clientCarsEntities[0].licensePlateNumber
        this.carModels = [
          this.fromdata.clientCarsEntities[0].carBrandId,
          this.fromdata.clientCarsEntities[0].carSeriesId,
          this.fromdata.clientCarsEntities[0].timeType,
          this.fromdata.clientCarsEntities[0].carModelId,
        ]
      }
      if (this.fromdata.faultRoads) {
        this.fromdata.faultRoadsList = this.fromdata.faultRoads.split(',')
      }
      if (this.fromdata.dailyRoads) {
        this.fromdata.dailyRoadsList = this.fromdata.dailyRoads.split(',')
      }
      if (this.fromdata.inStore) {
        this.fromdata.inStoreStr = this.fromdata.inStore + '天';
      }
      Array.isArray(this.fromdata.photosList) &&
        this.fromdata.photosList.forEach((item, index) => {
          this.fileList.push({
            name: index,
            url: getImageUrl(item),
          })
        })
    },
  },
  mounted() {
    // 获取员工信息
    let user = store.state.user
    this.fromdata.receiptsTime = moment(new Date()).format(
      'YYYY-MM-DD HH:mm:ss'
    )
    this.fromdata.receptionName = user.name
    this.fromdata.receptionId = user.id
    this.dict = getDict(['客户来源', '内部检测状态'])
    this.inTable[3].options = this.dict['内部检测状态']
    let id = this.$route.query.id
    let type = this.$route.query.type
    if (id) {
      this.fromdata.id = id
      this.turnWorkFrom.pickCarId = id
      this.detail(id)
      if (type === 'view') {
        this.disabled = true
        this.inTable[3].disabled = true
      }
    } else {
      this.getWorkOrderCode()
    }
  },
}
</script>
